﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Campus.Main.Basic.InsertValues;
using cpmntctrl;
using dbcntn;

namespace Campus.Main.Basic.Settings
{
    public partial class RoomForm : DefaultForm
    {
        public RoomForm()
        {
            InitializeComponent();
            aToDb=new ConnectionToDb(Helper.ConnectionString);
            Initialize();
            this.ContextMenuStrip = contextMenuStrip1;
            contextMenuStrip1.Click += ToolStripMenuItem_Click;
        }
        public override void Initialize()
        {
            aToDb.AddItem(comboBox1,"yurtdef");
            aToDb.AddItemDBGridView(dataGridView1,Query.Room);
            aToDb.AddItem(comboBox2,"pol");
            ControlComponent.UnVisibleCells(dataGridView1,0,1,2);
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length>0)
            {
                aToDb.InsertIntoTable("room","yurt_id","description","pol_id",Convert.ToInt32(comboBox1.SelectedValue),textBox1.Text,Convert.ToInt32(comboBox2.SelectedValue));
                string room = aToDb.SelectId( textBox1.Text);
                BedCountForm f=new BedCountForm(room);
                f.ShowDialog();
                Initialize();
                textBox1.Clear();
            }
            else
            {
                MessageBox.Show("Талааларды толтургула!!!");
            }
        }

        private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            List<string> data=new List<string>();
            ControlComponent.AddToList(data,dataGridView1,e,0,1,2,4);
            Room f=new Room(data);
            f.FormClosed += Bind;
            f.ShowDialog();
        }

        private void ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int current = dataGridView1.CurrentCell.RowIndex;
            string id=Convert.ToString(dataGridView1.Rows[current].Cells[0].Value);
            if (MessageBox.Show("Silmek istiyormusunuz?", "Dikkat", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
            {
                aToDb.DeleteTable("room", "id", id);
                MessageBox.Show("Silindi");
                Initialize();
            }
        }

        private void dataGridView1_Enter(object sender, EventArgs e)
        {

        }
    }
}
